package com.qfedu.demo;

import com.qfedu.mapper.AccountRowMapper;
import com.qfedu.pojo.Account;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.util.List;


public class Demo {
    public static void main(String[] args) {

        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();

        driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        driverManagerDataSource.setUrl("jdbc:mysql:///spring");
        driverManagerDataSource.setUsername("root");
        driverManagerDataSource.setPassword("980121");
        jdbcTemplate.setDataSource(driverManagerDataSource);

//        jdbcTemplate.execute("delete from account where id =8");

//        int update = jdbcTemplate.update("delete from account where id =7");
        //update 可以执行增删改  execute执行sql语句

     /*   int update = jdbcTemplate.update("delete from account where id =?", 6);
        System.out.println(update);*/
//
//        List<Account> list =
//                jdbcTemplate.query("select * from account where id > ? and money > ?", new AccountRowMapper(), 1,20.0);
//        List<Account> list2 =
//                jdbcTemplate.query("select * from account where id > ? and money > ?",new BeanPropertyRowMapper<Account>(Account.class), 1,10.0);
//
//        // list.stream().forEach(o-> System.out.println(o));
//
//        for (Account account : list) {
//            System.out.println(account);
//        }
//
//        for (Account account : list2) {
//            System.out.println(account);
//        }

        Long count = jdbcTemplate.queryForObject("select count(*) from account where money > ?", Long.class, 100.0);
        System.out.println(count);
    }
}
